const { tool,api,time } = getApp();
Page({
    data: {
        info:{},
        types:[{id:0,name:"全部课题"},{id:1,name:"审核通过课题"}],
        type_id:0,// 0-全部课题,1-通过课题       
        page: 0,                // 页码
        pagesize: 10,           // 单页数据量
        year: time.getYear(),   // 当前年份
        classList: [],          // 课题列表
        isLoding: false,        // 是否可以上拉加载
    },

  // 切换分类
  tabChange(e) {
    let { index } = e.detail;
    let type_id = this.data.types[index].id;
    this.setData({ type_id,page: 0,classList: [] });
    this.getClassList();
},



    // 获取课题列表
    getClassList() {
      const {type_id,pagesize,page,classList}=this.data;
        api.getStorage('userInfo').then(info=>{
          let open_id=info.open_id;
          tool.getTeacherTopic({open_id,type_id,page,pagesize}).then(list=>{
            classList.push(...list);
            this.setData({ classList,isLoding: list.length >= pagesize });
          })
        })
    },

    // 监听页面加载
    onLoad(options) {
        this.getClassList();
           
    },

    // 上拉加载
    onReachBottom() {
        let { isLoding,page } = this.data;
        if (isLoding) {
            page++;
            this.setData({ page })
            this.getClassList();
        } else api.showToast('暂无更多数据','none');
    },

})